<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher_rb.html">
                vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000046">description</a>&nbsp;&nbsp;
      <a href="#M000044">failure_message</a>&nbsp;&nbsp;
      <a href="#M000041">greater_than</a>&nbsp;&nbsp;
      <a href="#M000052">higher_than_high?</a>&nbsp;&nbsp;
      <a href="#M000050">higher_than_low?</a>&nbsp;&nbsp;
      <a href="#M000042">in</a>&nbsp;&nbsp;
      <a href="#M000040">less_than</a>&nbsp;&nbsp;
      <a href="#M000051">lower_than_high?</a>&nbsp;&nbsp;
      <a href="#M000049">lower_than_low?</a>&nbsp;&nbsp;
      <a href="#M000043">matches?</a>&nbsp;&nbsp;
      <a href="#M000045">negative_failure_message</a>&nbsp;&nbsp;
      <a href="#M000039">new</a>&nbsp;&nbsp;
      <a href="#M000047">override_method</a>&nbsp;&nbsp;
      <a href="#M000048">passes_validation_with_size</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000039" class="method-detail">
        <a name="M000039"></a>

        <div class="method-heading">
          <a href="#M000039" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(attachment_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000039-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 9</span>
 9:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">attachment_name</span>
10:           <span class="ruby-ivar">@attachment_name</span> = <span class="ruby-identifier">attachment_name</span>
11:           <span class="ruby-ivar">@low</span>, <span class="ruby-ivar">@high</span> = <span class="ruby-value">0</span>, (<span class="ruby-value">1.0</span><span class="ruby-operator">/</span><span class="ruby-value">0</span>)
12:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000046" class="method-detail">
        <a name="M000046"></a>

        <div class="method-heading">
          <a href="#M000046" class="method-signature">
          <span class="method-name">description</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000046-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 42</span>
42:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">description</span>
43:           <span class="ruby-node">&quot;validate the size of attachment #{@attachment_name}&quot;</span>
44:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000044" class="method-detail">
        <a name="M000044"></a>

        <div class="method-heading">
          <a href="#M000044" class="method-signature">
          <span class="method-name">failure_message</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000044-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 34</span>
34:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">failure_message</span>
35:           <span class="ruby-node">&quot;Attachment #{@attachment_name} must be between #{@low} and #{@high} bytes&quot;</span>
36:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000041" class="method-detail">
        <a name="M000041"></a>

        <div class="method-heading">
          <a href="#M000041" class="method-signature">
          <span class="method-name">greater_than</span><span class="method-args">(size)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000041-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 19</span>
19:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">greater_than</span> <span class="ruby-identifier">size</span>
20:           <span class="ruby-ivar">@low</span> = <span class="ruby-identifier">size</span>
21:           <span class="ruby-keyword kw">self</span>
22:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000042" class="method-detail">
        <a name="M000042"></a>

        <div class="method-heading">
          <a href="#M000042" class="method-signature">
          <span class="method-name">in</span><span class="method-args">(range)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000042-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 24</span>
24:         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">in</span> <span class="ruby-identifier">range</span>
25:           <span class="ruby-ivar">@low</span>, <span class="ruby-ivar">@high</span> = <span class="ruby-identifier">range</span>.<span class="ruby-identifier">first</span>, <span class="ruby-identifier">range</span>.<span class="ruby-identifier">last</span>
26:           <span class="ruby-keyword kw">self</span>
27:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000040" class="method-detail">
        <a name="M000040"></a>

        <div class="method-heading">
          <a href="#M000040" class="method-signature">
          <span class="method-name">less_than</span><span class="method-args">(size)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000040-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 14</span>
14:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">less_than</span> <span class="ruby-identifier">size</span>
15:           <span class="ruby-ivar">@high</span> = <span class="ruby-identifier">size</span>
16:           <span class="ruby-keyword kw">self</span>
17:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000043" class="method-detail">
        <a name="M000043"></a>

        <div class="method-heading">
          <a href="#M000043" class="method-signature">
          <span class="method-name">matches?</span><span class="method-args">(subject)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000043-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 29</span>
29:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">matches?</span> <span class="ruby-identifier">subject</span>
30:           <span class="ruby-ivar">@subject</span> = <span class="ruby-identifier">subject</span>
31:           <span class="ruby-identifier">lower_than_low?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">higher_than_low?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">lower_than_high?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">higher_than_high?</span>
32:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000045" class="method-detail">
        <a name="M000045"></a>

        <div class="method-heading">
          <a href="#M000045" class="method-signature">
          <span class="method-name">negative_failure_message</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000045-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 38</span>
38:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">negative_failure_message</span>
39:           <span class="ruby-node">&quot;Attachment #{@attachment_name} cannot be between #{@low} and #{@high} bytes&quot;</span>
40:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000052" class="method-detail">
        <a name="M000052"></a>

        <div class="method-heading">
          <a href="#M000052" class="method-signature">
          <span class="method-name">higher_than_high?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000052-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 77</span>
77:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">higher_than_high?</span>
78:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@high</span> <span class="ruby-operator">==</span> (<span class="ruby-value">1.0</span><span class="ruby-operator">/</span><span class="ruby-value">0</span>)
79:           <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">passes_validation_with_size</span>(<span class="ruby-ivar">@high</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>)
80:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000050" class="method-detail">
        <a name="M000050"></a>

        <div class="method-heading">
          <a href="#M000050" class="method-signature">
          <span class="method-name">higher_than_low?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000050-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 68</span>
68:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">higher_than_low?</span>
69:           <span class="ruby-identifier">passes_validation_with_size</span>(<span class="ruby-ivar">@low</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>)
70:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000051" class="method-detail">
        <a name="M000051"></a>

        <div class="method-heading">
          <a href="#M000051" class="method-signature">
          <span class="method-name">lower_than_high?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000051-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 72</span>
72:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lower_than_high?</span>
73:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@high</span> <span class="ruby-operator">==</span> (<span class="ruby-value">1.0</span><span class="ruby-operator">/</span><span class="ruby-value">0</span>)
74:           <span class="ruby-identifier">passes_validation_with_size</span>(<span class="ruby-ivar">@high</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
75:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000049" class="method-detail">
        <a name="M000049"></a>

        <div class="method-heading">
          <a href="#M000049" class="method-signature">
          <span class="method-name">lower_than_low?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000049-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 64</span>
64:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lower_than_low?</span>
65:           <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">passes_validation_with_size</span>(<span class="ruby-ivar">@low</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
66:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000047" class="method-detail">
        <a name="M000047"></a>

        <div class="method-heading">
          <a href="#M000047" class="method-signature">
          <span class="method-name">override_method</span><span class="method-args">(object, method, &amp;replacement)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000047-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 48</span>
48:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">override_method</span> <span class="ruby-identifier">object</span>, <span class="ruby-identifier">method</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">replacement</span>
49:           (<span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">object</span>; <span class="ruby-keyword kw">self</span>; <span class="ruby-keyword kw">end</span>).<span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
50:             <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">method</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">replacement</span>)
51:           <span class="ruby-keyword kw">end</span>
52:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000048" class="method-detail">
        <a name="M000048"></a>

        <div class="method-heading">
          <a href="#M000048" class="method-signature">
          <span class="method-name">passes_validation_with_size</span><span class="method-args">(new_size)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000048-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 54</span>
54:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">passes_validation_with_size</span>(<span class="ruby-identifier">new_size</span>)
55:           <span class="ruby-identifier">file</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;.&quot;</span>)
56:           <span class="ruby-identifier">override_method</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">:size</span>){ <span class="ruby-identifier">new_size</span> }
57:           <span class="ruby-identifier">override_method</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">:to_tempfile</span>){ <span class="ruby-identifier">file</span> }
58: 
59:           (<span class="ruby-identifier">subject</span> = <span class="ruby-ivar">@subject</span>.<span class="ruby-identifier">new</span>).<span class="ruby-identifier">send</span>(<span class="ruby-ivar">@attachment_name</span>).<span class="ruby-identifier">assign</span>(<span class="ruby-identifier">file</span>)
60:           <span class="ruby-identifier">subject</span>.<span class="ruby-identifier">valid?</span>
61:           <span class="ruby-identifier">subject</span>.<span class="ruby-identifier">errors</span>.<span class="ruby-identifier">on</span>(<span class="ruby-node">&quot;#{@attachment_name}_file_size&quot;</span><span class="ruby-node">&quot;#{@attachment_name}_file_size&quot;</span>).<span class="ruby-identifier">blank?</span>
62:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>